﻿package fwk.utiles 
{

import flash.display.*;
import flash.utils.*;	
	
public class HorlogeMain  {
	public var date:Object;
	public var aheure:Object;
	public var aminute:Object;
	public var aseconde:Object;
	public var horlogeLettres:Object;
		
	public function HorlogeMain(paheure:Object, paminute:Object, paseconde:Object, phorlogeLettres:Object) {
		this.aheure = paheure;
		this.aminute = paminute;
		this.aseconde = paseconde;
		this.horlogeLettres = phorlogeLettres;
	}
		
	public function getAllTime():Array {
		this.date = new Date();
		return new Array(this.date.hours, this.date.minutes, this.date.seconds);
	}
		
	private function getDateAngle(time:int, par:int):int {
		return int(360/par*time);
	}
	
	private function pivoterAiguille(element:Object, angle:int):void {
		element.rotation = angle; 
	}
	
	private function giveNumber(number:int):String {
		if(number < 10) {
		  return '0'+number.toString();
		} else {
		  return number.toString();
		}
	}
	
	public function makeHorloge() {
		var date:Array = this.getAllTime();
		var s:int = date[2];
		var m:int = date[1]*60+s;
		var h:int = date[0]*3600+m;
		//this.horlogeLettres.text = this.giveNumber(date[0])+':'+this.giveNumber(date[1])+':'+this.giveNumber(date[2]);
		
		this.pivoterAiguille(this.aheure, this.getDateAngle(h, 12*3600));
		this.pivoterAiguille(this.aminute, this.getDateAngle(m, 60*60));
		this.pivoterAiguille(this.aseconde, this.getDateAngle(s, 60));
	}
	
	public function repeat():void {
		setInterval(this.makeHorloge, 1000);
	}
}

}